home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / shazam11.zip / ED.INC < prev    next >
Text File  |  1991-11-04  |  7KB  |  163 lines

  1. const
  2.    FileSpec                  : string = '*.TXT' ;
  3.  
  4. function ExecDialog ( P : PDialog ; Data : pointer ) : word ;
  5. var
  6.    Result                    : word ;
  7. begin
  8.    Result                    := cmCancel ;
  9.    P                         := PDialog ( Application^.ValidView ( P ) ) ;
  10.    if P <> NIL then
  11.    begin
  12.       if Data <> NIL then P^.SetData ( Data^ ) ;
  13.       Result                 := DeskTop^.ExecView ( P ) ;
  14.       if ( Result <> cmCancel ) and
  15.          ( Data <> NIL ) then P^.GetData ( Data^ ) ;
  16.       Dispose ( P , Done ) ;
  17.    end ;
  18.    ExecDialog                := Result ;
  19. end ;
  20.  
  21. function CreateFindDialog : PDialog ;
  22. var
  23.    D                         : PDialog ;
  24.    Control                   : PView ;
  25.    R                         : TRect ;
  26. begin
  27.    R.Assign ( 0 , 0 , 38 , 12 ) ;
  28.    D                         := New ( PDialog , Init ( R , 'Find' ) ) ;
  29.    with D^ do
  30.    begin
  31.       Options                := Options or ofCentered ;
  32.       R.Assign ( 3 , 3 , 32 , 4 ) ;
  33.       Control                := New ( PInputLine , Init ( R , 80 ) ) ;
  34.       Insert ( Control ) ;
  35.       R.Assign ( 2 , 2 , 15 , 3 ) ;
  36.       Insert ( New ( PLabel , Init ( R , '~T~ext to find' , Control ) ) ) ;
  37.       R.Assign ( 32 , 3 , 35 , 4 ) ;
  38.       Insert ( New ( PHistory , Init ( R , PInputLine ( Control ) , 10 ) ) ) ;
  39.       R.Assign ( 3 , 5 , 35 , 7 ) ;
  40.       Insert ( New ( PCheckBoxes , Init ( R ,
  41.                NewSItem ( '~C~ase sensitive' ,
  42.                NewSItem ( '~W~hole words only' , NIL ) ) ) ) ) ;
  43.  
  44.       R.Assign ( 14 , 9 , 24 , 11 ) ;
  45.       Insert ( New ( PButton , Init ( R , 'O~K~' , cmOk , bfDefault ) ) ) ;
  46.       Inc ( R.A.X , 12 ) ; 
  47.       Inc ( R.B.X , 12 ) ;
  48.       Insert ( New ( PButton , 
  49.                      Init ( R , 'Cancel' , cmCancel , bfNormal ) ) ) ;
  50.       SelectNext ( FALSE ) ;
  51.    end ;
  52.    CreateFindDialog          := D ;
  53. end ;
  54.  
  55. function CreateReplaceDialog : PDialog ;
  56. var
  57.    D                         : PDialog ;
  58.    Control                   : PView ;
  59.    R                         : TRect ;
  60. begin
  61.    R.Assign ( 0 , 0 , 40 , 16 ) ;
  62.    D                         := New ( PDialog , Init ( R , 'Replace' ) ) ;
  63.    with D^ do
  64.    begin
  65.       Options                := Options or ofCentered ;
  66.       R.Assign ( 3 , 3 , 34 , 4 ) ;
  67.       Control                := New ( PInputLine , Init ( R , 80 ) ) ;
  68.       Insert ( Control ) ;
  69.       R.Assign ( 2 , 2 , 15 , 3 ) ;
  70.       Insert ( New ( PLabel , Init ( R , '~T~ext to find' , Control ) ) ) ;
  71.       R.Assign ( 34 , 3 , 37 , 4 ) ;
  72.       Insert ( New ( PHistory , Init ( R , PInputLine ( Control ) , 10 ) ) ) ;
  73.       R.Assign ( 3 , 6 , 34 , 7 ) ;
  74.       Control                := New ( PInputLine , Init ( R , 80 ) ) ;
  75.       Insert ( Control ) ;
  76.       R.Assign ( 2 , 5 , 12 , 6 ) ;
  77.       Insert ( New ( PLabel , Init ( R , '~N~ew text' , Control ) ) ) ;
  78.       R.Assign ( 34 , 6 , 37 , 7 ) ;
  79.       Insert ( New ( PHistory , Init ( R , PInputLine ( Control ) , 11 ) ) ) ;
  80.  
  81.       R.Assign ( 3 , 8 , 37 , 12 ) ;
  82.       Insert ( New ( PCheckBoxes ,
  83.                   Init ( R ,
  84.                      NewSItem ( '~C~ase sensitive' ,
  85.                      NewSItem ( '~W~hole words only' ,
  86.                      NewSItem ( '~P~rompt on replace' ,
  87.                      NewSItem ( '~R~eplace all' , NIL ) ) ) ) ) ) ) ;
  88.  
  89.       R.Assign ( 17 , 13 , 27 , 15 ) ;
  90.       Insert ( New ( PButton , Init ( R , 'O~K~' , cmOk , bfDefault ) ) ) ;
  91.       R.Assign ( 28 , 13 , 38 , 15 ) ;
  92.       Insert ( New ( PButton , Init ( R , 'Cancel' , cmCancel , bfNormal ) ) ) ;
  93.  
  94.       SelectNext ( FALSE ) ;
  95.    end ;
  96.    CreateReplaceDialog       := D ;
  97. end ;
  98.  
  99. function DoEditDialog ( Dialog : integer ; Info : pointer ) : word ; far ;
  100. var
  101.    R                         : TRect ;
  102.    T                         : TPoint ;
  103. begin
  104.    case Dialog of
  105.    edOutOfMemory :
  106.       DoEditDialog           := MessageBox ( 'Not enough memory for this operation.' ,
  107.                                              NIL , mfError + mfOkButton ) ;
  108.    edReadError :
  109.       DoEditDialog           := MessageBox ( 'Error reading file %s.' ,
  110.                                              @Info , mfError + mfOkButton ) ;
  111.     edWriteError :
  112.       DoEditDialog           := MessageBox ( 'Error writing file %s.' ,
  113.                                              @Info , mfError + mfOkButton ) ;
  114.     edCreateError :
  115.       DoEditDialog           := MessageBox ( 'Error creating file %s.' ,
  116.                                              @Info , mfError + mfOkButton ) ;
  117.     edSaveModify :
  118.       DoEditDialog           := MessageBox ( '%s has been modified. Save?' ,
  119.                                              @Info , mfInformation + mfYesNoCancel ) ;
  120.     edSaveUntitled :
  121.       DoEditDialog           := MessageBox ( 'Save untitled file?' ,
  122.                                              NIL , mfInformation + mfYesNoCancel ) ;
  123.     edSaveAs :
  124.       DoEditDialog           := ExecDialog ( New ( PFileDialog , Init ( FileSpec ,
  125.                                              'Save file as' , '~N~ame' , fdOkButton , 101 ) ) , Info ) ;
  126.     edFind :
  127.       DoEditDialog           := ExecDialog ( CreateFindDialog , Info ) ;
  128.     edSearchFailed :
  129.       DoEditDialog           := MessageBox ( 'Search string not found.' ,
  130.                                              NIL , mfError + mfOkButton ) ;
  131.     edReplace :
  132.       DoEditDialog           := ExecDialog ( CreateReplaceDialog , Info ) ;
  133.     edReplacePrompt :
  134.       begin
  135.    {- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  136.    Avoid placing the dialog on the same line as the cursor
  137.    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -}
  138.         R.Assign ( 0 , 1 , 40 , 8 ) ;
  139.         R.Move ( ( Desktop^.Size.X - R.B.X ) div 2 , 0 ) ;
  140.         Desktop^.MakeGlobal ( R.B , T ) ;
  141.         Inc ( T.Y ) ;
  142.         if TPoint ( Info ).Y <= T.Y then
  143.            R.Move ( 0 , Desktop^.Size.Y - R.B.Y - 2 ) ;
  144.         DoEditDialog         := MessageBoxRect ( R , 'Replace this occurence?' ,
  145.           NIL , mfYesNoCancel + mfInformation ) ;
  146.       end ;
  147.    end ;
  148. end ;
  149.  
  150. function OpenEditor ( FileName : FNameStr ; Visible : boolean ) : PEditWindow ;
  151. var
  152.    P                         : PView ;
  153.    R                         : TRect ;
  154. begin
  155.    DeskTop^.GetExtent ( R ) ;
  156.    P                         := Application^.ValidView (
  157.                                 New ( PEditWindow ,
  158.                                 Init ( R , FileName, wnNoNumber ) ) ) ;
  159.    if not Visible then P^.Hide ;
  160.    DeskTop^.Insert ( P ) ;
  161.    OpenEditor                := PEditWindow ( P ) ;
  162. end ;
  163.